component output="false" extends="AbsService" accessors="true" {

	// Delegate
	property name="CategoryDelegate" type="it.millemultimedia.easyBlog.delegate.CategoryDelegate";

	public it.millemultimedia.easyBlog.service.CategoryService function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.CategoryValidator function getValidator(){
		
		return getCategoryDelegate().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Category[] function getCategoryList( required String listStr, required String propertyName ){
	
		var list = getCategoryDelegate().createList( arguments.listStr, arguments.propertyName );
		
		return list;
	}
	
	public it.millemultimedia.easyBlog.model.Category function new(){
	
		var category = getCategoryDelegate().createInstance();
		
		return category;
	}
	
	public it.millemultimedia.easyBlog.model.Category function getCategory( required Any Category ){
		
		return getCategoryDelegate().read( arguments.Category );
	}
	
	public it.millemultimedia.easyBlog.model.Category[] function getCategories( required Any category ){
	
		return getCategoryDelegate().list( arguments.category );
	}
	
	public boolean function categoryExists( required Any Category ){
		var result = getCategoryDelegate().list( arguments.Category );
		
		return arrayLen( result ) gt 0;
	}
	
	public void function saveCategory( required Any Category ){
	
		transaction{
		
			try{
			
				if( arguments.Category.getIdCategory() eq 0 ){
				
					this.createCategory( arguments.Category );
				
				}else if( arguments.Category.getIdCategory() gt 0 ){
				
					this.updateCategory( arguments.Category );
				
				}else{
				
					throw( message="Category id property have undefined value." );
				
				}
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function createCategory( required Any Category ){
	
		transaction{
		
			try{
			
				getCategoryDelegate().create( arguments.Category );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function updateCategory( required Any Category ){
	
		transaction{
		
			try{
			
				getCategoryDelegate().update( arguments.Category );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function deleteCategory( required Any Category ){
	
		transaction{
		
			try{
			
				getCategoryDelegate().delete( arguments.Category );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
							
			}
			
		}
		
	}
	
}
